#!/usr/bin/perl
use warnings;
use strict;

#******************************************************************************
# File: 
#		perl.pl
# Recipe: 1.4
#		Converting Between Characters and Values
# Version:
#		0.1
# Author:
#   	Yubei Zhu
# Mail:
#		yubeizhu@gmail.com
# Created at:
#   	2012-08-17  
# Last Update:
#   	2012-08-17
# License: 
#		GPLv3	
#******************************************************************************

# Perl doesn't treat characters and numbers interchangeably.
# It treats string and numbers interchangeably

############################ Convertion of Number and String ############################

my $sString1 = "0";
my $sNum1 = 0;


# "0" will be convert to 0, then do numieric compare with 0
# You will recieve the warning if you turn on warnings flag
# But string and num are equal as 0
#print "1. Perl treats string and numbers interchangeably\n" if( $sNum1 == $sString1 );



my $sString2 = "123abc" ;
my $sNum2 = 123;
# "123abc" will be convert to 123, then do numieric compare with 123
# You will recieve the warning if you turn on warnings flag
# But string and num are equal 
#print "2. Perl treats string and numbers interchangeably\n" if( $sNum2 == $sString2 );

# number 123 here can use as string to compare with "123abc"
# Obviously, they are not the same string
#print "----Perl treats string and numbers interchangeably\n" if( $sNum2 eq $sString2 );

my $sString3 = "abc";
# "abc" will be convert to 0, then do numieric compare with 0
# You will recieve the warning if you turn on warnings flag
# But string and num are equal as 0
#print "3. Perl treats string and numbers interchangeably\n" if( $sNum1 == $sString3 );

# All the chars in perl are strings actually


############################ Convertion of Number and Char ############################
# using function ord chr
# char ===> num
# Single char
my $sChar = "e";
# Use ord to get a ascii number of single-char string
my $sNum = ord( $sChar );
print "Char:$sChar and Ascii:$sNum\n";

# Multiple chars
$sChar = "abc";
$sNum = ord($sChar);
print "Char:$sChar and Ascii:$sNum\n";

# num ===> char
$sChar = chr( $sNum );
print "Ascii:$sNum and Char:$sChar\n";


# using function sprintf/printf



# usint function unpack/pack
